#include "BluetoothSerial.h"

#include "zgn.h"



BluetoothSerial SerialBT;






void setup(){
  SerialBT.begin("first");             //初始化蓝牙设备名称   
  Serial.begin(115200);//设置串口波特率                
  Serial.println("The device started, now you can pair it with bluetooth!");
  Serial.println(166);

  pinMode(2, OUTPUT);
  digitalWrite(2,LOW);
  pinMode(0, INPUT);

  jianpan_init();


}

void loop(){
  if (SerialBT.available() > 0) {           //如果蓝牙有接收到数据
    long int  a =  SerialBT.read();
    Serial.println(a);          //读取蓝牙接收到的数据通过串口输出
     if(a==0x31){
        digitalWrite(2,HIGH);
    }
    if(a==0x32)
    {
        digitalWrite(2,LOW);
    }

  }
  if (Serial.available()) {                 //串口有数据可读
    SerialBT.write(Serial.read());          //蓝牙发送串口数据
    Serial.println(Serial.read());
    



  }
  if(digitalRead(0)==0){
    delay(200);
    if(digitalRead(0)==0){
       digitalWrite(2,LOW);
       SerialBT.write(0x32);
    }
  }
int aa =get_jian();

switch(aa){
    case 1 : digitalWrite(2,HIGH); break;
    case 2 : digitalWrite(2,LOW); break;
    case 15 : digitalWrite(2,HIGH); break;
    case 16 : digitalWrite(2,LOW); break;
    default:break;      
}

delay(20);
  

}